<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'', styles:'bootstrap,font-awesome,animate,style,bootstrap-table,layui-date,layui'}){}%>
</head>
<body>
<div id="uploadDetail">
<a class="import-detail btn btn-sm btn-danger" style="display: none"><i class="fa fa-trash" aria-hidden="true"></i> 导入</a>
</div>
<div id="toolbar" class="btn-group" style="margin-bottom:5px;">
	<a class="add-btn btn btn-sm btn-success"><i class="fa fa-plus" aria-hidden="true"></i> 新增发运计划</a>
	<a class="export-btn btn btn-sm btn-success" style="margin-left: 5px"><i class="fa fa-plus" aria-hidden="true"></i> 导出所有数据</a>
	&nbsp;&nbsp;&nbsp;<button  class=" layui-btn  layui-btn-sm"  style="margin-top: -6px;margin-left: -4px">
		<i class="fa fa-download" aria-hidden="true"></i> <a href="/excel/库存调拨模板.xlsx" download style="color: white">下载模板</a>
	</button>
</div>
<div class="wrapper wrapper-content">
	<div class="row">
		<div class="col-sm-12">
			<!-- START 右侧数据 -->
			<div class="ibox float-e-margins" style="margin-bottom: 0px;">
				<div class="ibox-content" style="padding:15px 20px 0px 20px;">
					<form id="search-form" role="form" class="form-horizontal" autocomplete="off">
						<div class="form-group" >
							<label class="control-label col-sm-1">状态:</label>
							<div class="col-sm-2">
								<select  name="createStatus" id="createStatus" class="form-control">
									<option value="">请选择</option>
									<option value="0">全部</option>
									<option value="1">待发运</option>
									<option value="2">已发运</option>
									<option value="3">已送货</option>
									<option value="4">已入库</option>
								</select>
							</div>
							<label class="control-label col-sm-1">SKU:</label>
							<div class="col-sm-2">
								<input type="text" id="createSku" name="createSku" placeholder="请输入SKU" class="form-control">
							</div>
							<label class="control-label col-sm-1">柜号:</label>
							<div class="col-sm-2">
								<input type="text" id="createNo" name="createNo" placeholder="请输入柜号" class="form-control">
							</div>

							<a class="search-btn btn btn-success" style="margin-bottom: 0px;">查询</a>
						</div>
					</form>
				</div>
			</div>
			<!-- START 操作按钮 -->
			<!-- START 数据表格 -->
			<table id="stockTable"
				   data-toolbar="#toolbar"
				   data-side-pagination="server"
				   data-pagination="true"
				   data-resizable="true"
				   data-side-pagination="server"
				   data-url="/sea/physical/stockCreate/findByCnd.do?createStatus=1"
				   data-page-size="15">
			</table>
			<!-- END 数据表格 -->

			<!-- END 右侧数据 -->
		</div>
	</div>
</div>

<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,bootstrap-table,bootstrap-table-zh-CN,layer,laydate,layui'}){}%>
<script>
    var $stockTable = $('#stockTable'),selections=[];
    $(function(){

    	$("#uploadDetail").hide();
        //START 表格配置
        $stockTable.bootstrapTable({
			detailView: true,
            columns: [
                {
                    title: '柜号',
                    field: 'createNo',
                    align: 'center',
                    valign: 'middle'
                },
				{
					title: '装柜仓库',
					field: 'createWareName',
					align: 'center',
					valign: 'middle'
				},
                {
                    title: '目的仓库',
                    field: 'createDestWareName',
                    align: 'center',
                    valign: 'middle'
                },{
					title: '总件数',
					field: 'createNumber',
					align: 'center',
					valign: 'middle'
				},{
					title: '总箱数',
					field: 'createBoxNumber',
					align: 'center',
					valign: 'middle'
				},{
					title: '总体积',
					field: 'createVolume',
					align: 'center',
					valign: 'middle'
				},{
					title: '状态',
					field: 'createStatus',
					align: 'center',
					valign: 'middle',
					formatter:function (v,r) {
						var result='';
						switch (v) {
							case 1:
								result='待发运';
								break;
							case 2:
								result='已发运';
								break;
							case 3:
								result='已送货';
								break;
							case 4:
								result='已入库';
								break;
							default:
								result='';
						}
						return result;
					}
				},{
					title: '创建时间',
					field: 'createOperateTime',
					align: 'center',
					valign: 'middle'
				},{
					title: '操作',
					field: 'operate',
					align: 'center',
					valign: 'middle',
					formatter: optFormatter
				}
            ],
            onLoadSuccess : function() {
				$(".import-btn").on('click',function () {
					var id = $(this).attr('data-val');
					importSkuMethod(id);
				});
				$('.detail-btn').on('click',function(){
					var id = $(this).attr('data-val');
					layer.open({
						type: 2,
						area: ['700px','500px'],
						content: ['/sea/physical/stockCreate/record.do?id='+id, 'yes']
					});
				});

				$('.del-btn').on('click',function(){
					var delid = $(this).attr('data-val'),delname = $(this).attr('data-val-name');
					layer.confirm('确定要删除当前？', {
						btn: ['确定','取消'],title:'提示'
					}, function(){
						var index = layer.load();
						$.post('/sea/physical/stockCreate/cancel.do',{id: delid},function(data){
							if( data.ok ){
								layer.close(index);
								layer.msg(data.msg,{icon: 1,time: 1500},function(){
									//刷新页面
									$stockTable.bootstrapTable('refresh');
								});
							}else{
								layer.msg(data.msg,{icon: 0,time: 1500});
							}
						});
					});
				});
            },
			onExpandRow: function (index, row, $detail) {
				InitSubTable(index, row, $detail);
			}
        });
        //END 表格配置

        //表格高度自适应
        $(window).resize(function () {
            $dealTable.bootstrapTable('resetView', {
                height: getHeight()
            });
        });
    });

	var cur_table;
	//初始化子表格(无线循环)
	function InitSubTable (index, row, $detail) {
		var parentId = row.id;
		cur_table = $detail.html('<table></table>').find('table');
		$(cur_table).bootstrapTable({
			url: '/sea/physical/stockCreate/findByCreateId',
			method: 'get',
			clickToSelect: true,
			queryParams: {createId: parentId},
			ajaxOptions: {createId: parentId},
			clickToSelect: true,
			uniqueId: "id",
			pageSize: 10,
			pageList: [10, 25],
			columns: [
				{
					field: 'createNo',
					title: '柜号'
				}, {
					field: 'createShipmentId',
					title: 'shipmentId'
				},{
					field: 'createSku',
					title: 'sku'
				},{
					field: 'productName',
					title: '商品名称'

				},{
					field: 'productColorName',
					title: '颜色'

				},{
					field: 'productCm',
					title: '尺码(CM)'

				},{
					field: 'productInch',
					title: '尺码(INCH)'

				},{
					field: 'createNumber',
					title: '数量'

				},{
					field: 'createPackage',
					title: '装箱量'

				},{
					field: 'createBoxNumber',
					title: '箱数'
				},{
					field: 'createVolume',
					title: '总体积'

				}],
			onLoadSuccess: function () {

			}
		});
	};

	//新增
	$('.add-btn').on('click',function(){//新增
		layer.open({
			title: false,
			closeBtn: 0,
			type: 2,
			area: ['100%','100%'],
			skin: 'layer-ext-espresso',
			content: ['/sea/physical/stockCreate/addpage.do', 'yes']
		});
	});

	function optFormatter(value,row) {
		var content = '';
		status = row.createStatus;
		content += '&nbsp;<button class="del-btn btn btn-xs btn-danger" data-val="'+row.id+'" title="删除"><i class="fa fa-trash-o"></i>  </button>';
		if(row.createStatus==1) {
			content += '&nbsp;<button class="import-btn btn btn-xs btn-success" data-val="' + row.id + '" title="导入明细"><i class="fa fa-upload"></i>  导入明细</button>';
		}
		content += '&nbsp;<button class="detail-btn btn btn-xs btn-default" data-val="' + row.id + '" title="查看记录"><i class="fa fa-github-alt"></i> 查看记录</button>';
		return content;
	}

	var createId;
	function importSkuMethod(id){
		createId=id;
		$('.import-detail').click();
	}

	// 条件查询
	$('.search-btn').on('click',function () {
		$stockTable.bootstrapTable('refresh', { url:'${ctxPath}/sea/physical/stockCreate/findByCnd.do?'+$('#search-form').serialize() });
	});

	layui.use('upload', function(){
		var upload = layui.upload;
		//执行实例
		upload.render({
			elem: '.import-detail', //绑定元素,
			accept:'file'
			,url: '/sea/physical/stockCreate/importSku' //上传接口
			,data: {
				createId: function(){
					return createId;
				}
			}
			,before:function () {
				index=layer.load(1, {
					shade: [0.1,'#fff'] //0.1透明度的白色背景
				});
			}
			,done: function(data){
				if( data.ok ){
					layer.msg(data.msg,{icon: 1,time: 3000},function(){
						//刷新页面
						$stockTable.bootstrapTable('refresh');
						layer.close(index);
					});

				}else{
					layer.msg(data.msg,{icon: 0,time: 5000},function () {
						layer.close(index);
					});
				}
			}
			,error: function(){
				//请求异常回调
			}
		});
	});

	$(".export-btn").on('click',function () {
		window.location.href='/sea/physical/stockCreate/export.do'+$('#search-form').serialize();
	});
</script>
</body>
</html>
